package com.ruoyi.controller;


import com.ruoyi.domain.common.ResponseResult;
import com.ruoyi.domain.entity.Comment;
import com.ruoyi.domain.vo.CommentPageVo;
import com.ruoyi.service.CommentService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RequestMapping("/comment" )
@RestController
@Tag(name = "评论模块接口")
public class CommentController {
    private static final Logger log = LoggerFactory.getLogger(CommentController.class);
    @Resource
    private CommentService commentService;

    @PostMapping("/addComment")
    @Operation(summary = "发布评论")
    public ResponseResult<Integer> addComment(@RequestBody Comment comment) {
        log.info("评论内容：{}", comment);
        commentService.addComment(comment);
        return ResponseResult.success(comment.getId());
    }

    @GetMapping("/list")
    @Operation(summary = "获取评论列表")
    public ResponseResult<CommentPageVo> list(@RequestParam Integer postId, @RequestParam(defaultValue = "1") Integer pageNo,
                                              @RequestParam(defaultValue = "30") Integer pageSize) {
        return ResponseResult.success(commentService.getCommentPageVo(postId,pageNo,pageSize));
    }

    @Operation(summary = "点赞 / 取消点赞")
    @PostMapping("/likeComment")
    public ResponseResult likeOrCancelLike(@RequestParam Integer commentId){
        commentService.likeOrCancelLike(commentId);
        return ResponseResult.success();
    }

    @Operation(summary = "删除自己发布的某条评论")
    @DeleteMapping("/deleteComment")
    public ResponseResult deleteComment(@RequestParam Integer commentId){
        commentService.deleteComment(commentId);
        return ResponseResult.success();
    }
}